﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.DynamicData;
using System.Collections.Specialized;

namespace Catalyst.Web.DynamicData
{
    /// <summary>
    /// The base class used by UserControls that implements an 'in' comparisson. 
    /// </summary>
    public abstract class InFilterUserControlBase : FilterTemplateUserControlBase
    {
        public abstract string ValueList { get; set; }
        public abstract TypeCode ValueType { get; }

        public override IEnumerable<Parameter> GetWhereParameters(IDynamicDataSource dataSource)
        {
            yield return new InExpressionParameter() { Name = Column.Name, ValueType = ValueType, ValueList = ValueList }; 
        }

        public override void LoadQueryStringParameters(NameValueCollection parameters)
        {
            ValueList = parameters[Column.Name];
        }

        public override NameValueCollection SaveQueryStringParameters()
        {
            NameValueCollection parameters = new NameValueCollection();
            parameters.Add(string.Format("{0}", Column.Name), ValueList);
            return parameters;
        }

        public override void Clear()
        {
            ValueList = string.Empty;
        }

    }
}
